// components/zy-navigator.js
const config = require('../../config');

// console.log(config)

Component({

    /**
     * 组件的属性列表
     */
    properties: {
        istabbar: Boolean
    },

    /**
     * 组件的初始数据
     */
    data: {
        pages_len: 0,
        safeArea_top: 0,
    },

    /**
     * 组件的方法列表
     */
    methods: {
        m_navigateback() {
            wx.navigateBack()
        },
        m_navigatehome() {
            // console.log('config.tabs[0].pagePath', config.tabs[0].pagePath);
            wx.switchTab({
                url:  '/' + config.tabs[0].pagePath,
            })
        }
    },

    pageLifetimes: {
        show() {
            if (this.data.navigate_title) {
                return;
            }
            let pages = getCurrentPages() ?? []
            let curPage = pages.at(-1);
            let curRoute = curPage?.route ?? '';
            // console.log(curRoute);
            let pageConfig = config?.pages[curRoute];
            this.setData({
                navigate_title: pageConfig?.navigationBarTitleText,
            })
        }
    },

    lifetimes: {
        attached() {
            // this.sysinfo = wx.getSystemInfoSync();
            let safeArea = wx.getMenuButtonBoundingClientRect()
            // console.log(this.sysinfo)
            let pages = getCurrentPages();
            this.setData({
               pages_len:  pages.length,
               safeArea_top: safeArea.top 
            })
        }
    }
})